package com.stone.business.jc.action;

/**
 * <pre>
 * 考试
 * @author 
 * </pre>
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.stone.business.jc.pojo.TKs;
import com.stone.business.jc.pojo.TKsRy;
import com.stone.business.jc.service.JcCommonService;

import frm.ssh.action.BaseAction;
import frm.ssh.exception.AppException;

public class KsAction extends BaseAction {
	
	private static final long serialVersionUID = -4647594073681054487L;

	private JcCommonService myService;
	
	private TKs entity;
	
	private String id;
	
	private List<TKsRy> ksryList;
	
	/**
	 * 进入详细页面
	 * @return
	 * @throws AppException
	 */
	public String initDetail() throws AppException {
		
		// 修改进入
		if (!"0".equals(id)) {
			
			this.entity = (TKs)myService.findById(Long.parseLong(id), TKs.class.getName());
			ksryList = myService.findListByHql(" from TKsRy where ksid = '" + id + "' order by userid desc");

			// 新建进入
		} else {
			
			this.entity = new TKs();
			this.entity.setId(Long.parseLong("0"));
			// 0 培训 1考试
			this.entity.setState(super.getSearchBean().getCon1());
			ksryList = new ArrayList<TKsRy>();

		}

		return SUCCESS;
	}
	
	/**
	 * 保存
	 * @return
	 * @throws AppException
	 */
	public String save() throws AppException {
		
		myService.saveKs(entity, this.ksryList);
		ksryList = myService.findListByHql(" from TKsRy where ksid = '" + entity.getId() + "' order by userid desc");
		super.setInfo("保存成功");
		
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @return
	 * @throws AppException
	 */
	public String delete() throws AppException {
		
		myService.deleteKs(id);
		
		return "DEL-SUCCESS";
		
	}
	
	public void deleteKsRy() throws Exception {
		myService.doDelAll(id, "TKsRy");
        super.getResponse().getWriter().print("{msg:'删除成功'}");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setMyService(JcCommonService myService) {
		this.myService = myService;
	}

	public TKs getEntity() {
		return entity;
	}

	public void setEntity(TKs entity) {
		this.entity = entity;
	}

	public List<TKsRy> getKsryList() {
		return ksryList;
	}

	public void setKsryList(List<TKsRy> ksryList) {
		this.ksryList = ksryList;
	}
	
	

}
